<template>
  <div class="td-patient-delection-overview">
    <mt-cell title="总价">
      <span>{{parseFloat(total).toFixed(2)}}元</span>
    </mt-cell>
    <mt-cell title="含采血费" v-if="$store.state.item.orderInfo.OtherCost>0">
      <span>{{parseFloat(utils$.subTransfer($store.state.item.orderInfo.OtherCost)).toFixed(2)}}元</span>
    </mt-cell>
    <mt-cell title="姓名">
      <span>{{user.UserName}}</span>
    </mt-cell>
    <mt-cell title="手机号">
      <span>{{user.MobilePhone}}</span>
    </mt-cell>
    <mt-cell title="身份证">
      <span>{{user.IDCard}}</span>
    </mt-cell>
    <mt-cell title="配偶姓名">
      <span>{{user.MateName}}</span>
    </mt-cell>
    <mt-cell title="配偶年龄">
      <span>{{user.MateAge}}岁</span>
    </mt-cell>
    <mt-cell title="采样医院">
      <span>{{$store.state.item.orderInfo.HospitalName}}</span>
    </mt-cell>
    <mt-cell title="主治医师">
      <span>{{$store.state.item.orderInfo.DoctorName}}</span>
    </mt-cell>
    <mt-cell
      title="寄送地址"
      v-if="$store.state.item.orderInfo.IsSendMaterials===1"
      :label="$store.state.item.orderInfo.Address"
    ></mt-cell>
    <mt-cell title="是否寄送物料">
      <span v-if="$store.state.item.orderInfo.IsSendMaterials===0">否</span>
      <span v-if="$store.state.item.orderInfo.IsSendMaterials===1">是</span>
    </mt-cell>
    <mt-cell title="已选检测项目："></mt-cell>
    <div class="test-item-list">
      <p v-for="(item,index) in $store.state.item.testItemList" :key="index">
        <span class="check"></span>
        <span>
          {{item.label}}
          <label>({{item.gender}})</label>
        </span>
        <span>{{item.price}}元</span>
      </p>
    </div>
    <div class="footer">
      <mt-header :title="`小计：${parseFloat(total).toFixed(2)}`">
        <router-link to="tdPatientDelectionSelectTestItem" slot="left">
          <mt-button>上一步</mt-button>
        </router-link>
        <mt-button slot="right" @click="btnSubmit();">提交</mt-button>
      </mt-header>
    </div>
  </div>
</template>

<script>
import UserOrderInfoService from "../../../../_services/user.order.info.service";
export default {
  name: "TianDingPatientDelectionOverviewComponent",
  data() {
    return {
      user: {},
      total: 0
    };
  },
  mounted() {
    this.user = this.utils$.dataFormat(
      JSON.parse(this.local$.getItem("tdUser"))
    );

    if (this.$store.state.item.orderInfo.OtherCost > 0) {
      this.total =
        this.$store.state.item.total +
        parseFloat(
          this.utils$.subTransfer(this.$store.state.item.orderInfo.OtherCost)
        );
    } else {
      this.total = this.$store.state.item.total;
    }
  },
  methods: {
    btnSubmit() {
      this.confirm$("提示", "确认提交订单吗?", {
        confirm: action => {
          this.indicator$.open("请稍后...");

          let orderInfo = this.$store.state.item.orderInfo;

          let params = {
            OrderID: orderInfo.OrderID,
            UserID: orderInfo.UserID,
            HospitalID: orderInfo.HospitalID,
            DoctorID: orderInfo.DoctorID,
            IsSendMaterials: orderInfo.IsSendMaterials,
            TotalFee: parseFloat(
              parseFloat(this.total).toFixed(2) * 100
            ).toFixed(0),
            AddressID: orderInfo.AddressID,
            ItemIds: orderInfo.ItemIds,
            PayPlatform: orderInfo.PayPlatform,
            PayType: orderInfo.PayType
          };

          console.log(params);

          UserOrderInfoService.createOrderInfo(params)
            .then(response => {
              if (response.Data !== null) {
                this.$router.push({ name: "tdOrder" });
              } else {
                this.toast$(`订单提交失败！`);
              }
            })
            .catch(error => {
              let logData = {};
              logData.status = error.response.status;
              logData.data = error.response.config.data;
              logData.message = error.response.data;
              logData.url = error.response.config.url;
              logData.type = "response.error";
              let logParams = {};
              logParams.Content = JSON.stringify(logData);
              logParams.IPAddress = "";
              this.CommonService.WriteLog(logParams).then();
            });
        }
      });
    }
  }
};
</script>
